/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package factory2;

import java.util.ArrayList;
import javax.swing.Timer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

/**
 *
 * @author wida46984148
 */
public class aux2 {

    Timer timer;
    public ArrayList<NauBase> anb = new ArrayList<NauBase>();
    public ArrayList<NauEnemiga> anbE = new ArrayList<NauEnemiga>();
    public ArrayList<Shoot> sb = new ArrayList<Shoot>();
    Shocks sk = new Shocks();
    int c = 123;
    NauBase nb;

    public void posicionaUnitatAmiga(float x, float y, NauBase nb) {
        nb.setLocation(x, y);
        anb.add(nb);
    }

    public void posicionaUnitatEnemiga(String nbE)  {
        try {
            if(!(nbE.equals("descanso"))){
                nb = Naves.nausEnemigues(nbE);
                nb.setLocation(nb.posX, nb.posY);
                anbE.add((NauEnemiga) nb);
            }
        } catch (Exception z) {
            System.err.println(z);
        }
    }

    public void posShoot(float x, float y, Shoot s) {
        s.setLocation(x, y);
        sb.add(s);
    }

    public void dibuixar(Graphics g, GameContainer gc) {
        try {
            for (NauBase n : anb) {
                if (n != null) {
                    n.render(gc, g);
                }
            }
            for (NauEnemiga n : anbE) {
                if (n != null) {
                    n.render(gc, g);
                }
            }
            for (Shoot n : sb) {
                if (n != null) {
                    n.render(gc, g);
                }
            }

        } catch (Exception e) {
        }
    }

    private void accio(int delta) {
        try {
            for (Shoot n : sb) {
                if (n != null) {
                    n.update(delta);
                }
            }
            for (NauEnemiga n : anbE) {
                if (n != null) {
                    n.update(delta);
                }
            }

        } catch (Exception e) {
        }
    }

    public void update(int delta) {
        try {

            accio(delta);
            for (NauEnemiga n : anbE) {
                sk.shocksControl(n.sbe, anbE, anb, sb);
            }
        } catch (Exception e) {
        }
    }
}
